package com.roy.minimq.remoting.domain.entity.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class ServiceThread implements Runnable {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final long JOIN_TIME = 90 * 1000;
    protected final Thread thread;
    protected volatile boolean stoped = false;

    public abstract String getServiceName();

    public ServiceThread(){
        this.thread = new Thread(this,this.getServiceName());
    }

    public void start(){
        this.thread.start();
    }

    public void shutdown(){
        stoped = true;
        this.thread.interrupt();
        try {
            thread.join(JOIN_TIME);
        } catch (InterruptedException e) {
            logger.error("Interrupted", e);
        }
    }

    protected boolean isStoped(){
        return this.stoped;
    }
}
